#include <cstdio>
using namespace std;

int n;
int a[100005];

int findFirst(int x) {
	if (x > a[n]) return -1;
	int l = 0, r = n, mid;
	while(l < r) {
		mid = (l + r) >> 1;
		if (a[mid] >= x) r = mid;
		else l = mid + 1; 
	}
	if (a[l] == x) return l;
	else return -1;
}

int findLast(int x) {
	if (x > a[n]) return -1;
	int left = 0, right = n, mid;
	while(left < right) {
        mid = (right + left + 1) / 2;
        if (a[mid] <= x) left = mid;
        else right = mid - 1;
    }
    return left;
}

int main() {
	int c;
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}

	long long ans = 0;

	for (int i = 1; i <= n;) {
		int nowx = a[i], lst = findLast(a[i]);
		int s, t;
		s = findFirst(a[i] + c);
		t = findLast(a[i] + c);
		if (s != -1 && t != -1) {
			ans += (lst - i + 1) * (t - s + 1);
		}
		i = lst + 1;
	}

	printf("%lld\n", ans);
	return 0;
}
